package com.andnnl.service.sms;


import com.andnnl.dao.sms.SendMobilesDao;
import com.andnnl.pojo.base.EmasUcinfo;
import com.andnnl.pojo.sms.SendMobiles;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * Created by oumingwei on 2019/5/28.
 */
@Service
public class EmasSMSService {

    @Autowired
    private SendMobilesDao sendMobiles;

    public List<SendMobiles> getList() {

        Map<String, Object> paras = new HashMap<>();
//        paras.put("uid", "andnnl");
        return sendMobiles.getSQLManager().select("sendMobiles.sample", SendMobiles.class, paras, 1L, 10L);
    }

    public Map getSendSmsList(PageQuery<SendMobiles> pageQuery) {
        Map result = new HashMap();
        sendMobiles.getSQLManager().pageQuery("sendMobiles.sample", SendMobiles.class, pageQuery);

        if (pageQuery.getList() != null && pageQuery.getList().size() > 0) {
            List<Object> cellList = new ArrayList<Object>();
            for (SendMobiles t : pageQuery.getList()) {

                //cell
                List<Object> rowsList = new ArrayList<Object>();
//				rowsList.add(t.getId());
                rowsList.add(t.getMobile());
                rowsList.add(t.getArea());
                Map<String, Object> cellMap = new HashMap<String, Object>();
                cellMap.put("id", t.getId());
                cellMap.put("cell", rowsList);
                cellList.add(cellMap);

            }

            result.put("rows", cellList);
            result.put("page", pageQuery.getPageNumber());
            result.put("pageSize", pageQuery.getPageSize());
            result.put("records", pageQuery.getTotalRow());
            result.put("total", pageQuery.getTotalPage());
            result.put("result", 1);
        }

        return result;
    }


    public  List<SendMobiles> getGroupList() {
        Map<String, Object> paras = new HashMap<>();
        return sendMobiles.getSQLManager().select("sendMobiles.group", SendMobiles.class, paras, 1L, 10L);
    }

//    @Transactional
    public void saveList(){
//        id	uid	taskId	templateId	mobile	mobileType	extNum	area	gateway	statusCode	status	result	msgId	clientMsgId	priority	price	cost	submitTime	sendTime	deliverTime	createdTime	reSend
//        3	chenss	6	888	18682121840	1	NULL	NULL	NULL	NULL	0	NULL	NULL	NULL	1	NULL	NULL	NULL	NULL	NULL	2019-06-10 12:00:00.000	0
        SendMobiles sm=new SendMobiles();
        sm.setUid("chenss");
        sm.setTemplateId(888);
        sm.setMobileType(1);
        sm.setMobile("18589025711");
        sm.setCreatedTime(new Date());
        int rs = sendMobiles.getSQLManager().insert(sm);
        System.out.println(rs);
        throw new RuntimeException("ssssssssss");

    }
}
